
compono.Balloon = new compono.Object("Balloon");
compono.Balloon.base = false;
compono.Balloon.delay = 1000;
compono.Balloon.currents = {};

compono.Balloon.show = function(scope, content, e){
	
	if(!this.base){
		this.base = this.getByID("message-balloon");
	}
	
	if(this.base.intervalID){
		clearTimeout(this.base.intervalID);
	}
	
	this.currents = scope;	
	
	if(!this.base._title){
		this.base._title = this.getByTagName("h3",this.base);
	}
	if(!this.base._text){
		this.base._text = this.getByTagName("p",this.base);
	}
	
	if(content.title)
	{
		this.base._title.innerHTML = content.title;
		this.base._title.style.display="block";
	}
	else if(this.base._title)
	{
		this.base._title.style.display="none";
	}
	
	if(content.text)
	{
		this.base._text.innerHTML = this.core.wiki.render(content.text);
		this.base._text.style.display="block";
	}
	else if(this.base._text)
	{
		this.base._title.style.display="none";
	}
	
	this.appendClassName("balloon-visible",this.base);
	this.position(this.base, scope, e);
}



compono.Balloon.hide = function(scope, ev){
	this.base.intervalID = setTimeout("compono.Balloon.afterTimeout()", this.delay);
}



compono.Balloon.position = function(element, scope, e){
	var top, left, body, csst="top", cssl="right", pos;
	
	/* 	IE Standard Mode || Gecko 	(document.documentElement)
		IE Quirks Mode 				(document.body)
		http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/index.html		*/
	body = document.documentElement || document.body;
	
	pos = this.findElementPosition(scope);
	
	top = pos.top - element.offsetHeight;
	left = pos.left;
	
	if((top - body.scrollTop) < 0){
		csst = "bottom";
		top = pos.top + scope.offsetHeight;
	}

	if((left + element.offsetWidth) > body.offsetWidth){
		cssl = "left";
		left = pos.left - element.offsetWidth;
	}
	
	if(element.quadrant){
		this.removeClassName(element.quadrant, element);
	}
	element.quadrant = "balloon-"+csst+"-"+cssl;
	this.appendClassName(element.quadrant, element);
	
	element.style.top = top + "px";
	element.style.left = left + "px";
	
}


compono.Balloon.afterTimeout = function(){
	this.removeClassName("balloon-visible",this.base);
	clearTimeout(this.base.intervalID);
	this.base.intervalID = -1;
}
